<?php 
include("util.php");
include("header.php");
$count_per_page = 50;
$page = intval($_GET['page']);
if ($page == null || $page < 1) {
  $page = 1;
}

$author = intval($_GET['author']);
if ($author == null) {
  $author = 0;
}

$conn = mysql_connect("127.0.0.1","root","");
mysql_select_db("xingtan");

$sql=sprintf("SELECT count(a.id) AS total FROM articles AS a, authors AS u WHERE a.author = u.id AND a.category >= 0 AND a.author=%d", $author);
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$total_pages = ceil($row['total'] / $count_per_page);

$sql=sprintf("SELECT a.id AS a_id, a.title AS a_title, a.digest AS a_digest, a.create_time AS a_create_time, 
    u.id AS u_id, u.name AS u_name, u.title AS u_title, u.url AS u_url 
    FROM articles AS a, authors AS u WHERE a.author = u.id AND a.category >= 0  AND a.author = %d ORDER BY a.id DESC limit %d", 
    $author, $page * $count_per_page);
$result = mysql_query($sql);
?>

<div class="container">
	<div class="main">
		<div class="content">
			<div class="articles">
        <div style="margin:4px 0 10px;font-size:18px;font-weight:bold;">
          <?php 
          $sql=sprintf("SELECT id, name, title, url FROM authors WHERE id=%d", $author);
          $author_info = mysql_query($sql);
          $row = mysql_fetch_array($author_info);
          if ($row) {
            printf('<a href="%s" target="_blank">%s</a>的所有文章', $row['url'], $row['name']);
          }
          ?> 
        </div>
<style type="text/css">
span.meta {
  margin-left:-0.6em;
}
span.meta a {
  display:none;
}
</style>
        <?php 
        CommonPageNav($total_pages, $count_per_page, $page, 3, sprintf("/u%d-%%d/", $author));
        print('<div class="article_body">');
        $index = 0;
        while($row = mysql_fetch_array($result)) {
          if ($index >= ($page - 1) * $count_per_page) {
            ArticlePreview($row['a_id']);
          }
          ++$index;
        }
        CommonPageNav($total_pages, $count_per_page, $page, 3, sprintf("/u%d-%%d/", $author));
        print('</div>');
        ?>
			</div>
		</div>
		</div>
    <?php include("back-top.php"); ?>
	</div>
</div>

<?php 
mysql_close($conn);
include("footer.php");
?>
